#-*-coding:utf-8-*-

from PyQt4 import QtCore, QtGui, QtNetwork
import os


class Download(QtNetwork.QHttp):
    def __init__(self, url):
        QtNetwork.QHttp.__init__(self)
        self.url = url.split("/")
        if os.path.isdir(os.path.join(os.getcwd(), "packages")) == False:
            os.mkdir("packages")
        self.path = QtCore.QFile(unicode(os.path.join(os.getcwd(), "packages", self.url[-1]), "utf-8"))
        self.setHost(self.url[2])
        pkg = self.url[3:]
        self.get("/%s" % "/".join(pkg), self.path)
        self.connect(self, QtCore.SIGNAL("done(bool)"), self.kapat)

    
    def kapat(self):
        self.path.close()


